/**
 * 2025/01/01 - 2025/12/31
 */
package com.snail.server.database.engine.ddl.index.controller;

import com.snail.server.database.engine.ddl.index.dto.IndexAddDTO;
import com.snail.server.database.engine.ddl.index.manager.IndexManager;
import com.snail.server.database.engine.ddl.index.vo.IndexVO;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 *
 * @author zgadmin
 * @date 2025/8/29 14:29
 *
 */
@Api(tags = {"索引管理"})
@RestController
@RequestMapping("/data-source/{dataSourceId}/table/{tableId}/index")
public class IndexController {

    @Resource
    IndexManager indexManager;

    @PostMapping
    public Long create(@PathVariable("dataSourceId") Long dataSourceId, @PathVariable("tableId") Long tableId, @RequestBody IndexAddDTO indexCreate){
        return indexManager.create(dataSourceId, tableId, indexCreate);
    }

    @PutMapping("/{indexId}")
    public boolean alter(@PathVariable("dataSourceId") Long dataSourceId, @PathVariable("tableId") Long tableId, @PathVariable("indexId") Long indexId){
        return indexManager.alter(dataSourceId, tableId, indexId);
    }

    @GetMapping("/{indexId}")
    public IndexVO queryById(@PathVariable("dataSourceId") Long dataSourceId, @PathVariable("tableId") Long tableId, @PathVariable("indexId") Long indexId){
        return indexManager.queryById(dataSourceId, tableId, indexId);
    }

    @DeleteMapping("/{indexId}")
    public boolean delete(@PathVariable("dataSourceId") Long dataSourceId, @PathVariable("tableId") Long tableId, @PathVariable("indexId") Long indexId){
        return indexManager.delete(dataSourceId, tableId, indexId);
    }

}